/**
 *	流程模块接口文件
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framework.Module.system.task;




import com.framerock.baselib.Rock;
import com.framework.ACore.Model;
import com.framework.ACore.Task;
import com.framework.Flow.FlowListener;
import com.framework.Model.ModelOption;

import java.util.Map;


public class FlowListenertask extends FlowListener {



    @Override
    public Boolean onRemind() {
        return true;
    }

    @Override
    public Boolean onModejs() {
        return true;
    }

    @Override
    public Map<String, String> onRemindInfo() {
        Map<String, String> da = Rock.getMap();
        da.put("name", "添加运行时间");
        da.put("fields", "ratecont"); //更新到对应主表字段
        da.put("nameview", "运行时间管理");
        return da;
    }

    //计划任务运行
    public Map<String, String> onRemindRuning() {

        Map<String, String> rs = mFlow.data,da = Rock.getMap();

        int status = Rock.getMapint(rs, "status");
        if(status == 0)return null; //停用就不运行了

        String url   = rs.get("url");
        String arr[] = url.split(",");
        String mod   = arr[0],act = "run";
        if(arr.length>1)act = arr[1];

        Task obj    = Task.taskObj(this.nDb, mod);
        obj.setRequest(mRequest);
        String str = obj.startQuery(act);
        Model.get(this.nDb, "task").update("`lastdt`=NOW()", mFlow.mid);

        da.put("result", str);

        return da;
    }

    @Override
    public String onAction(String act, String params) {
        if(act.equals("clearrun")) {
        	mFlow.mModel.update("`lastdt`=NULL","1=1");
        	ModelOption.get(this.nDb).setVal("tasklast", "");
        }
        //if(act.equals("taskstart"))this.taskstart();
        //if(act.equals("taskstop"))this.taskstop();
        return super.onAction(act, params);
    }

    //启动计划任务
    /*
    private void taskstart(){
        RockMsg rockmsg  = ChajianReim.obj(this.nDb).taskstart();
        if(rockmsg.isError())mFlow.setError(rockmsg.getMsg());
    }
    private void taskstop(){
        RockMsg rockmsg  = ChajianReim.obj(this.nDb).taskstop();
        if(rockmsg.isError())mFlow.setError(rockmsg.getMsg());
    }
     */


    public Map<String, String> onDataafter()
    {
        Map<String, String> da = Rock.getMap();
        
        da.put("tasklast", ModelOption.get(this.nDb).getVal("tasklast"));

        return da;
    }
}
